package cn.sinonet.filter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jt.classic.system.wordbook.XWordbook;
import jt.classic.system.wordbook.XWordbookMain;

import org.limp.basework.console.XSystemConfig;

public final class Special4Filter {

	private static String context = (String) XSystemConfig.config()
			.getProperty("XSYSTEM_CONTEXT");
	private static Map includeMap = new HashMap();

	public Special4Filter() {
	}

	public static synchronized boolean isContains(String container) {
		boolean result = false;

		System.out.println("context=" + context);

		if (container.equals(context)
				|| container
						.equals((new StringBuilder(String.valueOf(context)))
								.append("/").toString())) {
			result = true;
		} else {
			String subContainer = container.substring(context.length());
			if (subContainer.equals("/system/console")) {
				result = true;
			} else {
				String extension = subContainer.lastIndexOf(".") <= subContainer
						.lastIndexOf("/") ? "" : subContainer
						.substring(subContainer.lastIndexOf("."));
				result = includeMap.containsKey(subContainer)
						&& !includeMap.get(subContainer).equals("-1")
						|| includeMap.containsKey(extension)
						&& !includeMap.get(extension).equals("-1");
			}
		}
		return result;
	}

	public static synchronized void reloadFilterException() {
		if (!includeMap.isEmpty()) {
			includeMap.clear();
		}
		XWordbookMain wbmain = XWordbookMain.getInstance();
		List list = wbmain.getWord("filterException");
		if (list != null && !list.isEmpty()) {
			for (int i = 0; i < list.size(); i++) {
				XWordbook wb = (XWordbook) list.get(i);
				includeMap.put(wb.getID(), wb.getName());
			}

		}
	}

}
